package com.example.exercises;

import java.util.concurrent.*;

public class MyThreadPool extends ThreadPoolExecutor {
    public MyThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    }

    public MyThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
    }

    public MyThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
    }

    public MyThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
    }

}

class Init {
    static int b = 5;
    int a = 1;

    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool = new MyThreadPool(4, 8, 2, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(20));
        Init init = new Init();
        CountDownLatch countDownLatch = new CountDownLatch(1);
        myThreadPool.execute(() -> {
            init.zzz();
            b = 4;
            countDownLatch.countDown();
            init.sout();
        });
        System.out.println("----");
        countDownLatch.await();

    }

    void zzz() {
        a = b;
        a = 8;
    }

    void sout() {
        System.out.println(b + "---" + a);
    }
}